<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>编辑组织信息</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            line-height: 1.6;
            margin: 0;
            padding: 20px;
            background-color: #f5f5f5;
            color: #333;
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
            background: #fff;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }

        h2 {
            color: #2c3e50;
            border-bottom: 2px solid #3498db;
            padding-bottom: 10px;
            margin-top: 0;
        }

        .form-group {
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
            color: #555;
        }

        input[type="text"],
        input[type="file"],
        select,
        textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }

        textarea {
            min-height: 100px;
            resize: vertical;
        }

        .logo-container {
            display: flex;
            align-items: center;
            margin-bottom: 20px;
        }

        .logo-img {
            width: 100px;
            height: 100px;
            border-radius: 5px;
            object-fit: cover;
            margin-right: 20px;
            border: 2px solid #3498db;
        }

        .no-logo {
            color: #777;
            font-style: italic;
        }

        .btn {
            display: inline-block;
            padding: 10px 20px;
            background-color: #3498db;
            color: white;
            text-decoration: none;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s;
        }

        .btn-submit {
            background-color: #2ecc71;
        }

        .btn-back {
            background-color: #95a5a6;
        }

        .btn:hover {
            opacity: 0.9;
        }

        .btn-submit:hover {
            background-color: #27ae60;
        }

        .btn-back:hover {
            background-color: #7f8c8d;
        }

        .btn-group {
            margin-top: 30px;
            display: flex;
            gap: 10px;
        }

        .checkbox-group {
            margin: 15px 0;
        }

        .checkbox-group input {
            margin-right: 10px;
        }
    </style>
    <script>
        function previewImage(input) {
            const preview = document.getElementById('preview');
            const noLogoText = document.getElementById('noLogoText');

            if (input.files && input.files[0]) {
                const reader = new FileReader();

                reader.onload = function(e) {
                    preview.src = e.target.result;
                    preview.style.display = 'block';
                    if (noLogoText) {
                        noLogoText.style.display = 'none';
                    }
                }

                reader.readAsDataURL(input.files[0]);
            }
        }
    </script>
</head>
<body>
<div class="container">
    <h2>编辑组织信息</h2>
    <form action="${pageContext.request.contextPath}/organization/edit" method="post" enctype="multipart/form-data">
        <input type="hidden" name="orgid" value="${organization.orgid}">
        <input type="hidden" name="userid" value="${organization.users.userid}">

        <div class="logo-container">
            <c:choose>
                <c:when test="${not empty organization.logo}">
                    <img id="preview" class="logo-img" src="${organization.logo}" alt="当前Logo">
                </c:when>
                <c:otherwise>
                    <img id="preview" class="logo-img" style="display:none;">
                    <p id="noLogoText" class="no-logo">暂无Logo</p>
                </c:otherwise>
            </c:choose>
            <div>
                <div class="form-group">
                    <label for="logo">上传新Logo</label>
                    <input type="file" id="logo" name="logo" onchange="previewImage(this)">
                </div>
                <c:if test="${not empty organization.logo}">
                    <div class="checkbox-group">
                        <input type="checkbox" name="deleteLogo" id="deleteLogo">
                        <label for="deleteLogo" style="display: inline; font-weight: normal;">删除当前Logo</label>
                    </div>
                </c:if>
            </div>
        </div>

        <div class="form-group">
            <label for="org_name">组织名称</label>
            <input type="text" id="org_name" name="org_name" value="${organization.org_name}" required>
        </div>

        <div class="form-group">
            <label for="org_type">组织类型</label>
            <select id="org_type" name="org_type" required>
                <option value="公益组织" ${organization.org_type == '公益组织' ? 'selected' : ''}>公益组织</option>
                <option value="企业" ${organization.org_type == '企业' ? 'selected' : ''}>企业</option>
                <option value="学校" ${organization.org_type == '学校' ? 'selected' : ''}>学校</option>
                <option value="政府机构" ${organization.org_type == '政府机构' ? 'selected' : ''}>政府机构</option>
                <option value="其他" ${organization.org_type == '其他' ? 'selected' : ''}>其他</option>
            </select>
        </div>

        <div class="form-group">
            <label for="contact_phone">联系电话</label>
            <input type="text" id="contact_phone" name="contact_phone" value="${organization.contact_phone}" required>
        </div>

        <div class="form-group">
            <label for="address">地址</label>
            <input type="text" id="address" name="address" value="${organization.address}" required>
        </div>

        <div class="form-group">
            <label for="description">组织描述</label>
            <textarea id="description" name="description" required>${organization.description}</textarea>
        </div>

        <div class="btn-group">
            <input type="submit" class="btn btn-submit" value="提交">
            <a href="${pageContext.request.contextPath}/organization/list" class="btn btn-back">返回</a>
        </div>
    </form>
</div>
</body>
</html>